package com.example.chatgptapplication.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.chatgptapplication.annotation.Log;
import com.example.chatgptapplication.entity.Admin;
import com.example.chatgptapplication.entity.Tag;
import com.example.chatgptapplication.enums.BusinessType;
import com.example.chatgptapplication.enums.ResponseStatus;
import com.example.chatgptapplication.service.TagService;
import com.example.chatgptapplication.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.PipedReader;
import java.util.List;

@RestController
@RequestMapping("/tag")
public class TagController {


    @Autowired
    private TagService tagService;



    @Log(title = "新增Prompt",businessType = BusinessType.INSERT)
    @PostMapping("/addTag")
    public ResponseData addTag(@RequestBody Tag tag){
        tagService.save(tag);
        return new ResponseData(com.example.chatgptapplication.enums.ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMessage(), null);
    }

    @RequestMapping(value = "/listTag",method = RequestMethod.POST)
    public ResponseData listTag(@RequestBody Tag tag){
        Page<Tag> tagPage = tagService.listTagPage(tag);
        return new ResponseData(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMessage(), tagPage);
    }


    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public ResponseData list(){
        List<Tag> tags = tagService.list();
        return new ResponseData(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMessage(), tags);
    }



    @Log(title = "修改Prompt",businessType = BusinessType.UPDATE)
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public ResponseData updateById(@RequestBody Tag tag){
        tagService.updateById(tag);
        return new ResponseData(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMessage(), "修改成功!");
    }



    @Log(title = "删除Prompt",businessType = BusinessType.DELETE)
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public ResponseData deleteById(@RequestBody Tag tag){
        tagService.deleteTag(tag);
        return new ResponseData(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMessage(),"删除成功!");
    }




}
